package com.lsfb.testgamedemo;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.provider.Settings;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import com.lsfb.testgamedemo.Activity.ChargeActivity;
import com.lsfb.testgamedemo.Utils.CommonValue;
import com.lsfb.testgamedemo.Utils.SPUtils;
import com.lsfbandroid.helloplugin.R;

import org.xutils.x;
import org.xutils.view.annotation.ContentView;
import org.xutils.view.annotation.ViewInject;


@ContentView(R.layout.activity_second)
public class Main3Activity extends Activity implements View.OnClickListener {

    private String TAG = "nonsense";
    @ViewInject(R.id.end_time)
    private TextView end_time;

    @ViewInject(R.id.btn1)
    private Button btn1;

    @ViewInject(R.id.mingling_pwd)
    private TextView tv_ls;

    @ViewInject(R.id.ed_ls)
    private EditText ed_ls;

    @ViewInject(R.id.btn_ls)
    private Button btn_ls;

    @ViewInject(R.id.edt_time)
    private EditText ed_delay;

    @ViewInject(R.id.mingling_time)
    private TextView tv_delay;

    @ViewInject(R.id.btn_time)
    private Button btn_delay;

    private String delay;
    private int delayint = 500;

    @ViewInject(R.id.seed3)
    private CheckBox seed3;

    @ViewInject(R.id.seed2)
    private CheckBox seed2;

    @ViewInject(R.id.seed1)
    private CheckBox seed1;

    @ViewInject(R.id.charge)
    private Button btn_charge;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        x.view().inject(this);
//        delay = getResources().getString(R.string.delay);
//        String.format(delay, delayint);
//        tv_delay.setText(delayint + "");
        String ml = (String) SPUtils.get(getApplication(), "password", "123");
        if (ml != null) {
            tv_ls.setText(ml);
        }
        String sped = (String) SPUtils.get(getApplicationContext(), "speed", "2");
        if (sped != null) {
            switch (Integer.valueOf(sped)) {
                case 1:
                    seed1.setChecked(true);
                    break;
                case 2:
                    seed2.setChecked(true);
                    break;
                case 3:
                    seed3.setChecked(true);
                    break;
            }
        }
        btn_ls.setOnClickListener(this);
        btn_delay.setOnClickListener(this);
        btn1.setOnClickListener(this);
        seed1.setOnClickListener(this);
        seed2.setOnClickListener(this);
        seed3.setOnClickListener(this);
        btn_charge.setOnClickListener(this);
    }

    @Override
    protected void onResume() {

        super.onResume();
        if (!CommonValue.CanRun) {
            startActivity(new Intent(this, Main2Activity.class));
            CommonValue.CanRun=true;
            this.finish();
        }
        String sped = (String) SPUtils.get(getApplicationContext(), "speed", "2");
        if (sped != null) {
            switch (Integer.valueOf(sped)) {
                case 1:
                    seed1.setChecked(true);
                    break;
                case 2:
                    seed2.setChecked(true);
                    break;
                case 3:
                    seed3.setChecked(true);
                    break;
            }
        }
        String ml = (String) SPUtils.get(getApplication(), "password", "123");
        if (ml != null) {
            tv_ls.setText(ml);
        }
        end_time.setText(CommonValue.endtime);
    }

    @Override
    public void onClick(View v) {
        Log.e(TAG, "123");
        switch (v.getId()) {
            case R.id.btn1:
                Intent intent = new Intent(Settings.ACTION_ACCESSIBILITY_SETTINGS);
                startActivity(intent);
                break;
            case R.id.btn_ls:
                //修改验证密码
                if (!ed_ls.getText().toString().isEmpty()) {
                    SPUtils.remove(getApplication(), "password");
                    SPUtils.put(getApplication(), "password", ed_ls.getText().toString());
                    tv_ls.setText(ed_ls.getText().toString());
                    ed_ls.setText("");
                }
                break;
            case R.id.btn_time:
                break;
            case R.id.seed1:
                seed2.setChecked(false);
                seed3.setChecked(false);
                seed1.setChecked(true);
                SPUtils.put(this, "speed", "1");
                break;
            case R.id.seed2:
                seed1.setChecked(false);
                seed3.setChecked(false);
                seed2.setChecked(true);
                SPUtils.put(this, "speed", "2");
                break;
            case R.id.seed3:
                seed2.setChecked(false);
                seed1.setChecked(false);
                seed3.setChecked(true);
                SPUtils.put(this, "speed", "3");
                break;
            case R.id.charge:
                startActivity(new Intent(this, ChargeActivity.class));
                break;
        }
    }
    @Override
    public void onBackPressed() {
        // super.onBackPressed();
        Toast.makeText(x.app(), "请按home键返回桌面", Toast.LENGTH_LONG).show();
    }
}
